package com.zjdiepu.www.biz.base;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.base.core.BaseService;
import com.zjdiepu.www.base.enums.type.CodeType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.dao.base.SerialNumberMapper;
import com.zjdiepu.www.ibiz.base.ISerialNumberService;
import com.zjdiepu.www.util.ExceptionHelper;

/**
 * 序号生成Service层操作实现<br/>
 * @author xiongxiaotun<br/>
 * @time 2017年03月23日 10时52分<br/>
 * @since 1.0<br/>
 */
@Service
public class SerialNumberServiceImpl extends BaseService implements ISerialNumberService {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private SerialNumberMapper serialNumberMapper;
	
	@Override
	public Integer createSerialNumber(CodeType codeType, String prefix, boolean clean) {
		logger.debug("生成编号...");
		if(null == codeType) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();  
		paramMap.put("serialType", codeType.getCode());  
		paramMap.put("prefix", StringUtils.isBlank(prefix) ? null : prefix.trim());
		paramMap.put("clean", clean);  
		serialNumberMapper.generateSerialNumber(paramMap);
		return (Integer)paramMap.get("currentNumber");
	}
}

